﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DLULearningNetworkModel;
using DLULearningNetwork.ViewModels;
using DLULearningNetwork.Libs;
using DLULearningNetwork.ActionFilterAttributes;

namespace DLULearningNetwork.Controllers
{
    public class AdminAccountController : Controller
    {
        [RequireAdminLogin]
        public ActionResult Index(int? page)
        {
            int p = page.HasValue ? page.Value : 1;
            if(p < 1)
            {
                p = 1;
            }

            int totalItems = 0;
            List<Account> accounts = Account.Pager(p, 20, ref totalItems);
            return View(new AdminAccountViewModel(accounts, p, totalItems, 20, Constants.DEFAULT_PAGESIZE));
        }

        [RequireAdminLogin]
        [HttpPost]
        public int BanOrUnbanAccount(Guid id, bool isBanned)
        {
            Account account = Account.Single(id);
            if (account != null)
            {
                account.IsBanned_b = isBanned;
                return Account.Update(account);
            }
            else
            {
                return -1;
            }
        }
    }
}
